<template>
	<div class="entry_container">
		<k-header headTitle="注册" goBack="true"></k-header>
		<div :class="headIos?'archieve_container-ios':'entry_content'">
			<input class="entry-phone _input" placeholder="请输入手机号码" maxlength="11" v-model.trim="middle" >
			<div class="entry_yanzheng">
				<input type="text" class="entry-pass _input" maxlength="4" placeholder="请输入验证码" v-model="code">
				<button :disabled="kedianji" @click="kedian" class="kedian">{{data}}</button>
			</div>
			<button :disabled="idendiss" :class="{'disable':idendiss,'regentry':regshow}" @click="_idendiss" class="entry_prsee">注册</button>
			<span class="agreement">注册即代表阅读并已同意<router-link class="agree" to="agree">《用户协议》</router-link></span>
			<toast v-model="showPositionValue" type="text" width="100%" :time="1800" is-show-mask :text="message" position="bottom"></toast>
		</div>
	</div>
</template>

<script>
	import kHeader from '../common/head'
	import util from '../../libs/util';
	import { Toast} from 'vux';
	var iiTime;
	export default {
        data () {
            return {
            	data: '发送验证码',
            	code:'',
            	middle:'',
            	time: 60,
            	idendiss:false,
            	regshow:false,
            	regmiddle:false ,
            	showPositionValue:false,
							message:'请输入正确的手机号',
							headIos:false,
							kedianji:false,
            }
        },
        components: {
        	kHeader,
        	Toast
				},
				created(){
					if (window.navigator.userAgent.indexOf('LBLSIOS') > -1) {
						this.headIos = true
					} else {
						this.headIos = false
					};
				},
        methods: {
        	kedian : function(){
						this.kedianji=true;
        		var url ='/lblsapp-h5/v2/account/sendSMS.json';
        		let data={mobile:this.middle,source:'REGIST'};
        		var regtel = /^(0|86|17951)?(13[0-9]|15[012356789]|17[01356789]|18[0-9]|14[579])[0-9]{8}$/;
						let istel = regtel.test(this.middle);
						var that = this;
        		if(istel){
	        		this.data = 60 + 's';
	        		iiTime = setInterval(function(){
	        			that.time--;
	        			that.data = that.time + 's';
	        			if(that.time ==0){
									that.kedianji=false;
	        				that.data = '发送验证码';
	        				that.time = 60;
	        				clearInterval(iiTime);
	        			}
	        		},1000);
	        		util.ajax.post(url, data).then(function(data){
	        		 	if(data.data.code==='0'){
	        		 		
	        		 	}else{
									that.kedianji=false;
	        				that.data = '发送验证码';
	        				that.time = 60;
	        				clearInterval(iiTime);
	        		 		that.message = data.data.res.msg;
	        		 		that.showPositionValue=true;
	        		 	}
	        		}).catch(function(error){
	        			console.log(error);
	        		})
        		}else{
							this.kedianji = false;
        			this.message='请输入正确的手机号';
        			this.showPositionValue=true;
        		}
        		
					},
        	_idendiss : function(){
        		this.idendiss = true;
        		var url = 'lblsapp-h5/v2/account/regist.json';
        		let data={mobile:this.middle,smsCode:this.code}
        		var regtel = /^(0|86|17951)?(13[0-9]|15[012356789]|17[01356789]|18[0-9]|14[579])[0-9]{8}$/;
        		let istel = regtel.test(this.middle);
        		var that = this;
        		if(istel){
	        		util.ajax.post(url, data).then(function(data){
	        			if(data.data.code ==='0'){
	        				that.$cookie.set('mobole', that.middle, 50);
									that.$cookie.set('token', data.data.res.data , 50);
									that.$router.push({ path: '/userCertification', query: { mobile: '1' } })
	        			}else{
	        				that.message = data.data.res.msg;
	        				that.showPositionValue=true;
	        				that.idendiss = false;
	        			}
	        		}).catch(function(error){
	        			console.log(error);
	        			that.idendiss = false;
	        		})
        		}else{
        			this.idendiss=false;
        			this.message='请输入正确的手机号';
        			this.showPositionValue=true;
        		}
        	},
        	
        }
    }
</script>
<style type="text/css">
	.agreement{
		display: block;
		text-align: center;
		font-size: 12px;
		color: #808080;
	}
	.agree{
		font-size: 12px;
		color: #F89721;
	}
    .entry_prsee{
		margin: 55px 0 20px 0 !important;
    }
    .regentry{
    	margin-top: 0 !important;
    }
</style>